using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;

using MM.Entities;
using MM.Business; 

namespace MM
{
    public partial class frmTimPhieuYC_KetQua : Form
    {

        // the delegate the subscribers must implement
        public delegate void ChonPhieuYeuCau(object frmTimPhieuYC_KetQua, ChonPhieuYCEventArgs chonPYCevent);

        // an instance of the delegate
        public ChonPhieuYeuCau chonPYC;

        string _sConn = "";

        public int fBack = 0;

        public frmTimPhieuYC_KetQua(List<PHIEU_YEU_CAU> lst,string sConn)
        {
            InitializeComponent();
            _sConn = sConn;
            this.InitGrid(lst);
        }
        private void InitGrid(List<PHIEU_YEU_CAU> lst)
        {
            this.gridControl1.DataSource = lst;
        }

        private void gridDSVT_MouseDown(object sender, MouseEventArgs e)
        {
            GridHitInfo hi = (sender as GridView).CalcHitInfo(new Point(e.X, e.Y));
            if (hi.InRowCell && hi.Column.ColumnEdit is DevExpress.XtraEditors.Repository.RepositoryItemHyperLinkEdit)
            {
                GridView view = (sender as GridView);
                
                string maphieuyeucau = view.GetRowCellValue(hi.RowHandle, "MaPhieuYeuCau").ToString();

               

                ChonPhieuYCEventArgs pycevent = new ChonPhieuYCEventArgs(maphieuyeucau);

                if (chonPYC!=null)
                {
                    chonPYC(this, pycevent);
                }


            }
        }

        private void gridDSVT_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                
                int index = gridDSVT.FocusedRowHandle;
                if (index>=0)
                {
                    string maphieuyeucau = gridDSVT.GetRowCellValue(index, "MaPhieuYeuCau").ToString();

                    ChonPhieuYCEventArgs pycevent = new ChonPhieuYCEventArgs(maphieuyeucau);

                    if (chonPYC != null)
                    {
                        chonPYC(this, pycevent);
                    }
                }
            }
        }

        private void frmTimPhieuYC_KetQua_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Back)
            {
                fBack = 1;
                this.Close();
                this.Dispose();
            }
        }

        

       
    }

    class ChonPhieuYCEventArgs : EventArgs
    {
       public string MaPhieuYeuCau="";

        public ChonPhieuYCEventArgs(string mapyc)
        {
            MaPhieuYeuCau = mapyc;
        }
    }
}